home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / tools / bison.lha / bison++-1.04 / main.c < prev    next >
C/C++ Source or Header  |  1989-07-07  |  3KB  |  129 lines

  1. /* Top level entry point of bison,
  2.    Copyright (C) 1984, 1986, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of Bison, the GNU Compiler Compiler.
  5.  
  6. Bison is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. Bison is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with Bison; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include <stdio.h>
  22. #include "machine.h"    /* JF for MAXSHORT */
  23.  
  24. extern    int lineno;
  25. extern    int verboseflag;
  26.  
  27. /* Nonzero means failure has been detected; don't write a parser file.  */
  28. int failure;
  29.  
  30. char *parser_name = "Parser";
  31.  
  32. void
  33. main(argc, argv)
  34. int argc;
  35. char *argv[];
  36. {
  37.   failure = 0;
  38.   lineno = 0;
  39.   getargs(argc, argv);
  40.   openfiles();
  41.  
  42.   /* read the input.  Copy some parts of it to fguard, faction, ftable and fattrs.
  43.      In file reader.c.
  44.      The other parts are recorded in the grammar; see gram.h.  */
  45.   reader();
  46.  
  47.   /* find useless nonterminals and productions and reduce the grammar.  In
  48.      file reduce.c */
  49.   reduce_grammar();
  50.  
  51.   /* record other info about the grammar.  In files derives and nullable.  */
  52.   set_derives();
  53.   set_nullable();
  54.  
  55.   /* convert to nondeterministic finite state machine.  In file LR0.
  56.      See state.h for more info.  */
  57.   generate_states();
  58.  
  59.   /* make it deterministic.  In file lalr.  */
  60.   lalr();
  61.  
  62.   /* Find and record any conflicts: places where one token of lookahead is not
  63.      enough to disambiguate the parsing.  In file conflicts.
  64.      Currently this does not do anything to resolve them;
  65.      the trivial form of conflict resolution that exists is done in output.  */
  66.   initialize_conflicts();
  67.  
  68.   /* print information about results, if requested.  In file print. */
  69.   if (verboseflag)
  70.     verbose();
  71.   else
  72.     terse();
  73.  
  74.   /* output the tables and the parser to ftable.  In file output. */
  75.   output();
  76.   done(failure);
  77. }
  78.  
  79. /* functions to report errors which prevent a parser from being generated */
  80.  
  81. void
  82. fatal(s)
  83. char *s;
  84. {
  85.   extern char *infile;
  86.  
  87.   if (infile == 0)
  88.     fprintf(stderr, "fatal error: %s\n", s);
  89.   else
  90.     fprintf(stderr, "\"%s\", line %d: %s\n", infile, lineno, s);
  91.   done(1);
  92. }
  93.  
  94.  
  95. /* JF changed to accept/deal with variable args.  Is a real kludge since
  96.    we don't support _doprnt calls */
  97. /*VARARGS1*/
  98.  
  99. void
  100. fatals(fmt,x1,x2,x3,x4,x5,x6,x7,x8)
  101. char *fmt;
  102. {
  103.   char buffer[200];
  104.  
  105.   sprintf(buffer, fmt, x1,x2,x3,x4,x5,x6,x7,x8);
  106.   fatal(buffer);
  107. }
  108.  
  109.  
  110. void
  111. toomany(s)
  112. char *s;
  113. {
  114.   char buffer[200];
  115.  
  116.     /* JF new msg */
  117.   sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s);
  118.   fatal(buffer);
  119. }
  120.  
  121.  
  122. void
  123. berror(s)
  124. char *s;
  125. {
  126.   fprintf(stderr, "internal error, %s\n", s);
  127.   abort();
  128. }
  129.